/*
Coder: Dzlua
Email: 505544956@qq.com
Time : 2017/05/18
*/
#include <cmdline/cmdline.h>
#include "sock.h"
#include "task.h"

//not show console
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")

/*
    cstask -h 192.168.1.200 -p 80 -s "shutdown -s -t 60"
    cstask -h 192.168.1.200 -p 80 --shell "shutdown -a"
*/
int main(int argc, char** argv)
{
    cmdline::parser cmd;
    cmd.add<std::string>("host", 'h', "host name", true, "");
    cmd.add<int>("port", 'p', "port number", false, 80, cmdline::range(1, 65535));
    cmd.add<std::string>("type", 't', "protocol type", false, "http", cmdline::oneof<std::string>("http", "https", "ssh", "ftp"));
    cmd.add<std::string>("shell", 's', "the shell cmd will to run");

    cmd.set_program_name("cstask");
    cmd.parse_check(argc, argv);

    //----------------//
    CmdTask task;

    task.SetType(cmd.get<std::string>("type"));
    task.SetHost(cmd.get<std::string>("host"));
    task.SetPort(cmd.get<int>("port"));

    if (cmd.exist("shell")) {
        task.SetCmdType(CmdTask::CmdType::CMDTYPE_SHELL);
        task.SetArgs(cmd.get<std::string>("shell"));
    }

    task.Send();
    std::string re = task.Receive();

    return 0;
}
